<?php
namespace Crawl\Controller;
use Common\Controller\AdminbaseController;
// +----------------------------------------------------------------------
// | Date:2018年1月18日
// +----------------------------------------------------------------------
// | Author: EK_熊<1439527494@qq.com>
// +----------------------------------------------------------------------
// | Description: 此文件作用于****
// +----------------------------------------------------------------------
class ResultController extends AdminbaseController{
    
    protected $model;
    public function _initialize(){
        $this->model = M('Crawl');
    }
    
    public function index(){
        $start_date = I('start_date');
        $end_date = I('end_date');
        $keyword = I('keyword');
        $channel = I('channel');
        if ($start_date && $end_date)
            $where['created_time'] = ['between',["$start_date 00:00:00","$end_date 23:59:59"]];
        if ($channel)
            $where['channel'] = $channel;
        if ($keyword)
            $where['keyword'] = $keyword;
        $list = $this->lists($this->model,$where,$order='id desc');
        $allkeyword = M('CrawlKeyword')->getField('key',true);
        
        $allchannel = $this->model->group('channel')->getField('channel',true);
        
        $this->assign('keyword',$allkeyword);
        $this->assign('channel',$allchannel);
        $this->assign('map',urlencode(json_encode($where)));
        $this->assign('list',$list);
        $this->display();
    }
    
    public function printexcel(){
        $filename_ch = '舆情监控报表';
        $filename = $filename_ch.date('Ymd',time());
        $map = I('map');
        $map = json_decode(urldecode($map),true);
        $list = $this->model->where($map)->select();
        $this->assign('list',$list);
        header("Content-type: application/vnd.ms-excel; charset=utf8");
        header("Content-Disposition: attachment; filename=$filename.xls");
        $this->display('index_print');
    }
    
    
}